<?php

class DbmHistorySearch extends DbmHistory {
	
	public $begin_time;
	public $end_time;

	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	public function rules() {
		return array(
			array('table_name, begin_time, end_time', 'safe', 'on'=>'search')
		);
	}
	
	public function attributeLabels() {
		return array_merge(parent::attributeLabels(), array(
			'begin_time' => '修改时间从',
			'end_time' => '到',
		));
	}
	
	public function only($table_name) {
		$this->dbCriteria->addCondition("table_name=:table_name");
		$this->dbCriteria->params[':table_name'] = $table_name;
		return $this;
	}
	
	public function desc($attribute) {
		$criteria = new CDbCriteria(array('order'=>$attribute . ' DESC'));
		$this->dbCriteria->mergeWith($criteria);
		return $this;
	}
	
	public function search() {
		
		$criteria = new CDbCriteria();
		$criteria->compare('table_name', $this->table_name);
		if($this->begin_time || $this->end_time) {
			$criteria->addBetweenCondition('create_time', $this->begin_time, $this->end_time);
		}
		
		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
			'pagination' => array(
				'pageSize' => 5,
			),
		));
		
	}
	

}

?>